package main

import (
	"fmt"
	"net"
	"time"
)

// 模拟客户端
func main() {
	// 直连远程服务器，得到一个conn链接
	fmt.Println("client start.......")
	time.Sleep(1 * time.Second) //挂起1s
	conn, err := net.Dial("tcp", "127.0.0.1:8999")
	if err != nil {
		fmt.Println("client start err,exit")
		return
	}

	for {
		//链接调用Write 写数据
		_, err := conn.Write([]byte("hello zinx V0.1..")) //返回的字节数暂时不关心
		if err != nil {
			fmt.Println("write conn err", err)
			return
		}
		buf := make([]byte, 512)
		cnt, err := conn.Read(buf)
		if err != nil {
			fmt.Println("read buf error")
			return
		}
		fmt.Printf("severr call back:%s,cnt=%d\n", buf, cnt)
		//CPU阻塞，否则会无限循环

		time.Sleep(1 * time.Second) //每隔一秒发一次 hello zinx V0.1..
	}

}
